package homework;

import org.junit.Test;

import java.util.Arrays;
import java.util.Random;

public class Randomarraytest {

        @Test
        public void test01(){
            int count=0;
            while(count<10){
                //采用边界测试法:从1-7之间生成6个随机数
                int [] arr= randomArray(6,33);
                System.out.println(Arrays.toString(arr));
                count++;
            }

        }

        public int[] randomArray(int length,int bound){
            int [] result=new int[length];
            boolean[]flag=new boolean[bound+1];
            Random r=new Random();
            for(int i=0;i<length;i++){
                int temp=r.nextInt(bound)+1;
                if(flag[temp]){
                    i--;
                    System.out.println("重复出现");
                }else{
                    result[i]=temp;
                    flag[temp]=true;
                }

            }
             

            return result;
        }
    }
